<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>FusionCharts v3 Documentation</title>
<link rel="stylesheet" href="Style.css" type="text/css" />
</head>

<body>
<table width="98%" border="0" cellspacing="0" cellpadding="3" align="center">
  <tr> 
    <td><h2 class="pageHeader">Using FusionCharts with C# (ASP.NET)&gt; Creating Drill-down charts </h2></td>
  </tr>
  <tr> 
    <td valign="top" class="text"><p>In our previous example, we had used FusionCharts to plot a chart using data stored in database. We'll now extend that example itself to create a drill-down chart which can show more information.</p>
    <p>If you recall from previous example, we were showing the sum of factory output in a pie chart as under: </p></td>
  </tr>
  <tr>
    <td valign="top" class="text"><img src="Images/Code_DBOut.jpg" width="572" height="273" class="imageBorder" /></td>
  </tr>
  <tr>
    <td valign="top" class="text">In this example, we'll extend this example, so that when a user clicks on a pie slice for a factory, he can drill down to see date wise production for that factory. </td>
  </tr>
  <tr>
    <td valign="top" class="text">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" class="header">Setting up the pie chart for Link </td>
  </tr>
  <tr>
    <td valign="top" class="text">To set up the pie chart to enable links for 
					drill-down involves just minor tweaking of our previous <span class="codeInline">BasicDBExample.aspx</span>. We basically need to add 
	the <span class="codeInline">link</span> attribute for each<span class="codeInline"> &lt;set&gt;</span> element. We create a new page <span class="codeInline">Default.aspx</span> from the previous page in <span class="codeInline">DBExample</span> folder with the following code changes:</td>
  </tr>
  <tr>
    <td valign="top" class="codeBlock"><p>
    &lt;%@ Page language="c#" Codebehind="BasicDBExample.aspx.cs" AutoEventWireup="false" Inherits="InfoSoftGlobal.GeneralPages.ASP.NET.DBExample.BasicDBExample" %&gt;
    <br>
&lt;HTML&gt;<br>
	&nbsp;&nbsp;&nbsp;&lt;HEAD&gt;<br>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;TITLE&gt;FusionCharts - Database Example &lt;/TITLE&gt;<br>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;SCRIPT LANGUAGE="Javascript" SRC="../../FusionCharts/FusionCharts.js"&gt;&lt;/SCRIPT&gt;<br>
		&nbsp;&nbsp;&nbsp;&lt;/HEAD&gt;<br>
	&nbsp;&nbsp;&nbsp;&lt;body&gt;<br>
	<strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong>&lt;form id='form1' name='form1' method='post' runat=&quot;server&quot;&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&nbsp;&nbsp;&nbsp;&lt;%=GetFactorySummaryChartHtml()%&gt; </strong><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/form&gt;<br>
	&nbsp;&nbsp;&nbsp;&lt;/body&gt;<br>
&lt;/HTML&gt;<br>
<br><br>

		<strong>public string GetFactorySummaryChartHtml()</strong><br>
		{			&nbsp;<br>
			<span class="codeComment">&nbsp;//xmlData will be used to store the entire XML document generated</span><br>
			&nbsp;string xmlData;<br>
<br>
			<span class="codeComment">&nbsp;//Generate the chart element</span><br>
			&nbsp;<chart caption='Factory Output report' subCaption='By Quantity' pieSliceDepth='30' showBorder='1' formatNumberScale='0' numberSuffix=' Units'>xmlData = &quot;&lt;chart caption='Factory Output report' subCaption='By Quantity' pieSliceDepth='30' showBorder='1' formatNumberScale='0' numberSuffix=' Units' animation=' &quot; + animateChart + &quot;'&gt;&quot;;<br>
	<br>
			<span class="codeComment">&nbsp;//Iterate through each factory</span><br>
			&nbsp;string factoryQuery = "select * from Factory_Master";<br>
			&nbsp;using (OdbcConnection connectin = FusionCharts.Connection(FusionCharts.ConnectionStringFactory))<br>
			&nbsp;{<br>
				&nbsp;&nbsp;using (OdbcCommand factoryCommand = new OdbcCommand(factoryQuery, connectin))<br>
				&nbsp;&nbsp;{<br>
					&nbsp;&nbsp;&nbsp;using (OdbcDataAdapter adapter = new OdbcDataAdapter(factoryCommand))<br>
					&nbsp;&nbsp;&nbsp;{<br>
						&nbsp;&nbsp;&nbsp;&nbsp;DataTable table = new DataTable();<br>
						&nbsp;&nbsp;&nbsp;&nbsp;adapter.Fill ( table );<br>
<br>
						&nbsp;&nbsp;&nbsp;&nbsp;foreach ( DataRow row in table.Rows)<br>
						&nbsp;&nbsp;&nbsp;&nbsp;{<br>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string quantityQuery = "select sum(Quantity) as TotOutput from Factory_Output where FactoryId=" + row["FactoryId"].ToString();<br>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;using (OdbcCommand quantityCommand = new OdbcCommand(quantityQuery,connectin))<br>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>
								&nbsp;&nbsp;&nbsp;&nbsp;<strong>&nbsp;&nbsp;xmlData += &quot;&lt;set label='&quot; + row[&quot;FactoryName&quot;].ToString() + &quot;' value='&quot; + <br />
								quantityCommand.ExecuteScalar().ToString() + &quot;' link='&quot; + <br />
								Server.UrlEncode(&quot;Detailed.aspx?FactoryId=&quot; + row[&quot;FactoryId&quot;].ToString()) + &quot;'/&gt;&quot;;</strong><br>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
						&nbsp;&nbsp;&nbsp;&nbsp;}<br>
					&nbsp;&nbsp;&nbsp;}<br>
				&nbsp;&nbsp;}<br>
				&nbsp;&nbsp;connectin.Close();<br>
<br>
				xmlData += "&lt;/chart&gt;</chart>";<br>
			&nbsp;}<br>
	<br>
			<span class="codeComment">&nbsp;//Create the chart - Pie 3D Chart with data from xmlData</span><br>
			<strong>&nbsp;return FusionCharts.RenderChart("../../FusionCharts/Pie3D.swf", "", xmlData, "FactorySum", "600", "300", false, false);</strong><br>
		}<br>
    </p></td>
  </tr>
  <tr>
    <td valign="top" class="text"><p>As you can see in the code above, we're doing the 
						following:</p>
      <ol>
        <li> Include <span class="codeInline">FusionCharts.js</span> JavaScript class to enable easy embedding of FusionCharts.</li>
        <li> We then open a connection using <span class="codeInline"> </span>to Access database.</li>
        <li> Thereafter, we generate the XML data in the <span class="codeInline">GetFactorySummaryChartHtml() </span>method document by 
          iterating through the recordset. We store the XML data in <span class="codeInline">xmlData</span> variable. To each <span class="codeInline">&lt;set&gt;</span> element, we add the <span class="codeInline">link</span> attribute, which points to <span class="codeInline">Detailed.aspx</span> - the page that contains the chart to show details. We pass the factory id of 
          the respective factory by appending it to the link. We finally URL Encode the 
          link, which is a very important step. </li>
        <li> Finally, we render the chart using <span class="codeInline">RenderChart()</span> method and pass <span class="codeInline">xmlData</span> as <span class="codeInline">dataXML</span>. </li>
      </ol>
      <p>Let's now shift our attention to <span class="codeInline">Detailed.aspx</span> page. </p></td>
  </tr>
  <tr>
    <td valign="top" class="text">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" class="header">Creating the detailed data chart page </td>
  </tr>
  <tr>
    <td valign="top" class="text">The page <span class="codeInline">Detailed.aspx</span> contains the following code: </td>
  </tr>
  <tr>
    <td valign="top" class="codeBlock"><p>
    %@ Page language="c#" Codebehind="Detailed.aspx.cs" AutoEventWireup="false" Inherits="InfoSoftGlobal.GeneralPages.ASP.NET.DBExample.Detailed" %&gt;<br>
    &lt;HTML&gt;<br>
	&nbsp;&nbsp;&nbsp;&lt;HEAD&gt;<br>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;TITLE&gt;FusionCharts - Database and Drill-Down Example &lt;/TITLE&gt;<br>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;SCRIPT LANGUAGE="Javascript" SRC="../../FusionCharts/FusionCharts.js"&gt;&lt;/SCRIPT&gt;
		<br>
	&nbsp;&nbsp;&nbsp;&lt;/HEAD&gt;<br>
	&nbsp;&nbsp;&nbsp;&lt;body&gt;
	<br>
		&nbsp;&nbsp;&nbsp;<strong>&nbsp;&nbsp;</strong>&lt;form id='form1' name='form1' method='post' runat=&quot;server&quot;&gt; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;%=GetFactoryDetailedChartHtml()%&gt;</strong><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/form&gt;<br>
	&nbsp;&nbsp;&nbsp;&lt;/body&gt;<br>
&lt;/HTML&gt;<br>
<br><br>
    		<strong>public string GetFactoryDetailedChartHtml()</strong><br>
		{<br>
			<span class="codeComment">&nbsp;//This page is invoked from Default.aspx. When the user clicks on a pie<br>
&nbsp;//slice in Default.aspx, the factory Id is passed to this page. We need<br>
&nbsp;//to get that factory id, get information from database and then show<br>
&nbsp;//a detailed chart.</span><br>
	<br>
			&nbsp;<span class="codeComment">//First, get the factory Id</span><br>
			&nbsp;string factoryId;<br>
			<span class="codeComment">&nbsp;//Request the factory Id from Querystring</span><br>
			&nbsp;factoryId = Request.QueryString["FactoryId"];<br>
<br>
			<span class="codeComment">&nbsp;//xmlData will be used to store the entire XML document generated</span><br>
			&nbsp;string xmlData;	<br>
	<br>
			&nbsp;<span class="codeComment">//Generate the chart element string</span><br>
			&nbsp;xmlData = &quot;&lt;chart palette='2' caption='Factory &quot; + factoryId +&quot; Output ' subcaption='(In Units)' xAxisName='Date' showValues='1' labelStep='2' &gt;&quot;;<br>
			<span class="codeComment">&nbsp;//Now, we get the data for that factory</span><br>
			&nbsp;string query = "select * from Factory_Output where FactoryId=" + factoryId;<br>
			&nbsp;using (OdbcConnection connection = FusionCharts.Connection(FusionCharts.ConnectionStringFactory))<br>
			&nbsp;{<br>
				&nbsp;&nbsp;using (OdbcCommand command = new OdbcCommand(query, connection))<br>
				&nbsp;&nbsp;{<br>
					&nbsp;&nbsp;&nbsp;using (OdbcDataReader reader = command.ExecuteReader())<br>
					&nbsp;&nbsp;&nbsp;{<br>
						&nbsp;&nbsp;&nbsp;&nbsp;while (reader.Read())<br>
						&nbsp;&nbsp;&nbsp;&nbsp;{<br>
							&nbsp;&nbsp;&nbsp;<strong>&nbsp;&nbsp;xmlData +=&quot;&lt;set label='&quot; + ((DateTime)reader[&quot;DatePro&quot;]).Day.ToString() +<br />
&quot;/&quot; + ((DateTime)reader[&quot;DatePro&quot;]).Month.ToString() + &quot;' value='&quot; + reader[&quot;Quantity&quot;].ToString() + &quot;'/&gt;&quot;;</strong><br>
						&nbsp;&nbsp;&nbsp;&nbsp;}<br>
						&nbsp;&nbsp;&nbsp;&nbsp;reader.Close();<br>
					&nbsp;&nbsp;&nbsp;}<br>
				&nbsp;&nbsp;}<br>
			&nbsp;}<br>
<br>
			&nbsp;<span class="codeComment">//Close 
			<chart> element</chart>
			</span>
			<chart><br>
			&nbsp;xmlData += "</chart>
			&lt;/chart&gt;";<br>
	<br>
			<span class="codeComment">&nbsp;//Create the chart - Column 2D Chart with data from xmlData</span><br>
			<strong>&nbsp;return FusionCharts.RenderChart("../../FusionCharts/Column2D.swf", "", xmlData, "FactoryDetailed", "600", "300", false, false);</strong><br>
		}<br>
    </p>    </td>
  </tr>
  <tr>
    <td valign="top" class="text"><p>In this page, we're:</p>
      <ol>
        <li> Including <span class="codeInline">FusionCharts.js</span> JavaScript class to enable easy embedding of FusionCharts.</li>
        <li> Requesting the factory id for which we've to show detailed data. This data was 
          sent to us as querystring, as a part of pie chart link.</li>
        <li> We get the requisite data for this factory from database and then convert it 
          into XML using string concatenation.</li>
        <li> Finally, we render a Column 2D chart using <span class="codeInline">RenderChart()</span> method to show detailed data.</li>
      </ol>
      <p>When you now run the app, you'll see the detailed page as under: </p></td>
  </tr>
  <tr>
    <td valign="top" class="text"><img src="Images/Code_Drill.jpg" width="599" height="292" class="imageBorder" />&nbsp;</td>
  </tr>
</table>
</body>
</html>
